#ifndef TDDGUI_BUTTONS_H
#define TDDGUI_BUTTONS_H

#include <atlbase.h>
#include <atlctrls.h>
#include <atldlgs.h>

#include "UiInterfaces.h"

namespace TddGui
{

class BaseButton : public CWindowImpl<BaseButton, CButton>
{
public:
	virtual ~BaseButton() {}

	BEGIN_MSG_MAP(BaseButton)
		REFLECTED_COMMAND_CODE_HANDLER (BN_CLICKED, OnClicked)
		DEFAULT_REFLECTION_HANDLER();
	END_MSG_MAP()

	void Init(HWND hwnd)
	{
		SubclassWindow (hwnd);
	}

private:
	virtual LRESULT OnClicked (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) = 0;
};


template <typename CFileDialog>
class LoadButtonT : public BaseButton
{
	LoadNotification& m_tv;

public:
	LoadButtonT(LoadNotification& subjectTreeView)
		: m_tv(subjectTreeView)
	{}

private:
	virtual LRESULT OnClicked (WORD , WORD , HWND , BOOL& bHandled)
	{
		CFileDialog wfd(TRUE, L"dll", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, L"Test Dlls(*.dll)\0*.dll\0All Files(*.*)\0*.*\0\0", *this);

		if (IDCANCEL != wfd.DoModal(*this))
		{
			m_tv.LoadTests(CPath(wfd.m_szFileName));
		}
		return bHandled = TRUE;
	}
};
typedef LoadButtonT<WTL::CFileDialog> LoadButton;


class RunButton : public BaseButton, public EnableNotification
{
	RunNotification& m_runTests;
public:
	RunButton(RunNotification& subjectRunTests)
		: m_runTests(subjectRunTests)
	{}

private:
	virtual LRESULT OnClicked (WORD , WORD , HWND , BOOL& bHandled)
	{
		m_runTests.Run();
		return bHandled = TRUE;
	}
	virtual void Enable(bool b)
	{
		EnableWindow(b);
	}
};

}

#endif
